{ "cells": [ { "cell_type": "markdown", "id": "31e14143", "metadata": {}, "source": [ "## Delete Elements" ] }, { "cell_type": "code", "execution_count": 2, "id": "4fd8fcaa", "metadata": {}, "outputs": [], "source": [ "names=['Sahil','Sonia','Sourav']\n", "age=[10,20,30]" ] }, { "cell_type": "markdown", "id": "2a62ba08", "metadata": {}, "source": [ "### Remove first element" ] }, { "cell_type": "code", "execution_count": 7, "id": "e446c774", "metadata": {}, "outputs": [ { "data": { "text/plain": [ "'Sahil'" ] }, "execution_count": 7, "metadata": {}, "output_type": "execute_result" } ], "source": [ "names.pop(0) # in pop,pass the index" ] }, { "cell_type": "markdown", "id": "8320f51c", "metadata": {}, "source": [ "### Remove last element" ] }, { "cell_type": "code", "execution_count": 4, "id": "b736a0eb", "metadata": {}, "outputs": [ { "data": { "text/plain": [ "'Sourav'" ] }, "execution_count": 4, "metadata": {}, "output_type": "execute_result" } ], "source": [ "names.pop()" ] }, { "cell_type": "code", "execution_count": 8, "id": "2002917f", "metadata": {}, "outputs": [], "source": [ "names=['Sahil','Sonia','Sourav']" ] }, { "cell_type": "markdown", "id": "665f0329", "metadata": {}, "source": [ "### Remove any element based on position" ] }, { "cell_type": "code", "execution_count": 9, "id": "861138e3", "metadata": {}, "outputs": [ { "data": { "text/plain": [ "'Sourav'" ] }, "execution_count": 9, "metadata": {}, "output_type": "execute_result" } ], "source": [ "names.pop(2)" ] }, { "cell_type": "markdown", "id": "d03b6799", "metadata": {}, "source": [ "### Remove any element based on value" ] }, { "cell_type": "code", "execution_count": 10, "id": "00feda79", "metadata": {}, "outputs": [], "source": [ "names.remove('Sahil')" ] } ], "metadata": { "kernelspec": { "display_name": "Python 3", "language": "python", "name": "python3" }, "language_info": { "codemirror_mode": { "name": "ipython", "version": 3 }, "file_extension": ".py", "mimetype": "text/x-python", "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", "version": "3.8.8" } }, "nbformat": 4, "nbformat_minor": 5 }